package com.syezon.wifikey.wifi.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.syezon.android.base.utils.ToastUtils;
import com.syezon.wifikey.R;
import com.syezon.wifikey.wifi.info.BlackWifiInfo;
import com.syezon.wifikey.wifi.BlackWifiService;
import com.syezon.wifikey.wifi.info.WifiInfo;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/9/11.
 */

public class AddBlackConfirmDialog extends Dialog {

    @BindView(R.id.tv_cancel)
    TextView mTvCancel;
    @BindView(R.id.tv_confirm)
    TextView mTvConfirm;
    private WifiInfo wifiInfo;

    public AddBlackConfirmDialog(@NonNull Context context) {
        this(context, 0);
    }

    public AddBlackConfirmDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        setContentView(View.inflate(context, R.layout.dialog_add_black_alert, null));
        ButterKnife.bind(this);
    }

    public void setWifiInfo(WifiInfo wifiInfo) {
        this.wifiInfo = wifiInfo;
    }

    @Override
    public void show() {
        getWindow().setGravity(Gravity.CENTER);
        getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
        super.show();
    }

    @OnClick({R.id.tv_cancel, R.id.tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_cancel:
                dismiss();
                break;
            case R.id.tv_confirm:
                addBlackWifi();
                break;
        }
    }

    private void addBlackWifi() {
        BlackWifiInfo blackWifiInfo = new BlackWifiInfo();
        blackWifiInfo.setSsid(wifiInfo.getSsid());
        blackWifiInfo.setTime(System.currentTimeMillis());
        BlackWifiService.getInstance().addBlackWifi(blackWifiInfo);
        dismiss();
        getOwnerActivity().finish();
        ToastUtils.showShort("添加成功！");
    }
}
